// 这里是所有接口的集合
import http from './index'
import qs from 'querystring'

// ========菜单列表信息===========
//1. 获取菜单列表

export const menulist = () => {
  return http.get('/menulist', {
    params: {
      istree: true
    }
  })
}
// 添加菜单
export const menuAdd = (data) => {
  return http.post('/menuadd', qs.stringify(data))
}
// 删除菜单
export const menuDel = (data) => http.post('/menudelete', qs.stringify(data))

// 获取一条菜单数据
export const menuInfo = (data) => http.get('/menuinfo', {
  params: data
})
// 修改菜单数据
export const menuEdit = (data) => http.post('/menuedit', data)

// ----------------------------角色-------------------------------

// 角色列表/api/rolelist
export const roleList = () => http.get('/rolelist')
// 角色添加api/roleadd
export const roleAdd = (data) => http.post('/roleadd', data)
// 角色修改/api/roleedit
export const roleEdit = (data) => http.post('/roleedit', data)
// 角色删除- /api/roledelete
export const roleDelete = (data) => http.post('/roledelete', data)

// 获取一条角色信息/api/roleinfo
export const roleInfoa = (data) => http.get('/roleinfo', {
  params: data
})

// ------------------------------管理员-----------------------------
// 管理员列表/api/userlist
export const userList = (data) => http.get('/userlist', {
  params: data
})
// 管理员添加/api/useradd
export const userAdd = (data) => http.post('/useradd', data)
// 管理员修改/api/useredit
export const userEdit = (data) => http.post('/useredit', data)
// 管理员删除- /api/userdelete
export const userDelete = (data) => http.post('/userdelete', data)
// 获取管理员年数据一条/api/userinfo
export const getuserInfo = (data) => http.get('/userinfo', {
  params: data
})
// 管理员总条数/api/usercount
export const userCount = () => http.get('/usercount')

// 管理员的登录/api/userlogin
export const userlogin = (data) => http.post('/userlogin', qs.stringify(data))

// 商品分类列表/api/catelist
export const catelist = () => http.get('/catelist', {
  params: {
    istree: true
  }
})
// 商品分类添加/api/cateadd
export function addCate(data) {
  let file = new FormData()
  for (let i in data) {
    file.append(i, data[i]);

  }
  return http.post('/cateadd', file)
}

// 商品分类获取一条
export const cateinfo = (data) => http.get('/cateinfo', {
  params: data
})

// 商品分类修改/api/cateedit
export function cateedit(data) {
  let file = new FormData()
  for (let i in data) {
    file.append(i, data[i]);

  }
  return http.post('/cateedit', file)
}

// 商品分类删除
//分类单条删除
export function deleteCate(data) {
  //注意不能转化 Content-Type（内容类型）: application/x-www-form-urlencoded
  return http.post("/catedelete", data);
}
/* 商品规格管理接口 */
//商品规格添加
export function getSpecsAdd(data) {
  return http.post("/specsadd", qs.stringify(data));
}
//商品规格列表
export function getSpecs(data) {
  return http.get("/specslist", {
    params: data
  });
}
//商品规格获取（一条）
export function getSpecsInfo(params) {
  return http.get("/specsinfo", {
    params,
  });
}
//商品规格修改
export function getSpecsEdit(data) {
  return http.post("/specsedit", qs.stringify(data));
}
//商品规格删除
export function getSpecsDelete(data) {
  return http.post("/specsdelete", qs.stringify(data));
}
//商品规格总数（用于计算分页)
export function getSpecsCount() {
  return http.get("/specscount");
}

/* 商品管理接口 */
//商品管理添加
export function getGoodsAdd(data) {
  //因为是带有文件上传，所以入参要利用js去转化它的格式
  let file = new FormData();
  //利用循环对象的方式给数据data转化
  for (let i in data) {
    file.append(i, data[i]);
  }
  return http.post("/goodsadd", file);
}
//商品管理列表
export function getGoodsList(params) {
  return http.get("/goodslist", {
    params,
  });
}
//商品管理获取（一条）
export function getGoodsInfo(params) {
  return http.get("/goodsinfo", {
    params,
  });
}
//商品管理修改
export function getGoodsEdit(data) {
  //因为是带有文件上传，所以入参要利用js去转化它的格式
  let file = new FormData();
  //利用循环对象的方式给数据data转化
  for (let i in data) {
    file.append(i, data[i]);
  }
  return http.post("/goodsedit", file);
}
//商品管理删除
export function getGoodsDelete(data) {
  return http.post("/goodsdelete", data);
}
//商品管理总数（用于计算分页)
export function getGoodsCount() {
  return http.get("/goodscount");
}

// 秒杀添加/api/seckadd
export const seckadd = (data) => http.post('/seckadd', data)
// 秒杀列表/api/secklist
export const secklist = () => http.get('/secklist')
// 秒杀获取一条/api/seckinfo
export const seckinfo = (data) => http.get('/seckinfo', {
  params: data
})
// 秒杀修改/api/seckedit
export const seckedit = (data) => http.post('/seckadd', data)
// 秒杀删除/api/seckdelete
export const seckdelete = (data) => http.post('/seckdelete', data)